package com.zb.test;

import com.zb.bean.Employee;
import org.junit.Test;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 构造器引用：
 *  className::new
 */
public class JAVA8_5_构造器引用 {
    @Test
    public void test(){
        //普通Lambda表达式写法
        Supplier<Employee> supplier = () -> new Employee();//调用一个无参数的构构造器
        System.out.println(supplier.get());

        Function<Integer,Employee> function = (x) -> new Employee(x);//调用一个有参的构造器，参数类型可以根据上下文推断得出
        System.out.println(function.apply(1));

        BiFunction<Integer,String,Employee> biFunction = (x,y) -> new Employee(x,y);
        System.out.println(biFunction.apply(2," zhangbin"));

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        //构造器引用 写法
        //根据函数式接口中抽象方法的参数去找到被调用的构造器
        Supplier<Employee> supplier1 = Employee::new;//调用一个无参的构造器
        System.out.println(supplier1.get());

        Function<Integer,Employee> function1 = Employee::new;
        System.out.println(function1.apply(1));

        BiFunction<Integer,String,Employee> biFunction1 = Employee::new;
        System.out.println(biFunction1.apply(2,"张斌"));

    }
}
